package com.recharge.controller;

import com.recharge.base.ResponseInfo;
import com.recharge.base.ResponseInfoEnum;
import com.recharge.wk.domain.Supplier;
import com.recharge.wk.mapper.ITradeSupplierMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by qi.cao on 2017/1/24.
 */
@Controller
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private ITradeSupplierMapper iTradeSupplierMapper;

    @RequestMapping("/queryList")
    @ResponseBody
    public ResponseInfo queryList(@RequestParam("supplierId") String supplierId,
            @RequestParam("supplierName") String supplierName,
            @RequestParam("curr") Integer curr,
            @RequestParam("pageSize") Integer pageSize){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setInfoEnum(ResponseInfoEnum.SUCCESS);
        Supplier supplier = new Supplier();
        supplier.setSupplierId(supplierId);
        supplier.setSupplierName(supplierName);
        List<Supplier> suppliers = iTradeSupplierMapper.selectList(supplier, curr, pageSize);

        responseInfo.setCount(iTradeSupplierMapper.count(supplier));
        responseInfo.setData(suppliers);
        return responseInfo;
    }


    @RequestMapping("/updateInfo")
    @ResponseBody
    public ResponseInfo updateInfo(@RequestParam("supplierId") String supplierId,
                                  @RequestParam("supplierStatus") Boolean supplierStatus){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setInfoEnum(ResponseInfoEnum.SUCCESS);
        Supplier supplier = new Supplier();
        supplier.setSupplierId(supplierId);
        supplier.setSupplierStatus(supplierStatus);
        iTradeSupplierMapper.update(supplier);
        return responseInfo;
    }
}
